package net.qhzw.vip.qiyu.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.qhzw.vip.qiyu.dto.ShopAccountQuery;
import net.qhzw.vip.qiyu.entity.ShopAccount;
import net.qhzw.vip.qiyu.mapper.ShopAccountMapper;
import net.qhzw.vip.qiyu.service.ShopAccountService;
import net.qhzw.vip.qiyu.util.PageAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopAccountServiceImpl extends ServiceImpl<ShopAccountMapper, ShopAccount>
        implements ShopAccountService {

    @Autowired
    private ShopAccountMapper shopAccountMapper;


    @Override
    public double getBalance(Long shopId) {
        Double balance = shopAccountMapper.selectBalance(shopId);
        if (balance != null) {
            return balance;
        }
        return 0;
    }

    @Override
    public IPage<ShopAccount> findByPage(Page page, ShopAccountQuery query) {
        IPage<ShopAccount> pageInfo = new Page<>();
        List<ShopAccount> records = shopAccountMapper.selectByList(new PageAdapter(page), query);
        Long total = shopAccountMapper.selectByTotal(query);
        pageInfo.setRecords(records);
        pageInfo.setTotal(total);
        return pageInfo;
    }
}
